home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol07 / 03 / ole2 / initsvr.c
Text File  |  1992-05-01  |  4KB  |  132 lines

  1. /* From WinMain: */
  2.  
  3.     :
  4.     :
  5.  
  6.     if (!InitInstance(hInstance, fFirstInstance))
  7.         return FALSE;
  8.  
  9.     if (!InitServer (hwndMain, hInstance))
  10.         return FALSE;
  11.  
  12.     :
  13.     :
  14.  
  15.  
  16.  
  17. /* InitInstance
  18.  * ------------
  19.  *
  20.  * Do any per-instance initialization.
  21.  *
  22.  * HANDLE hInstance
  23.  * 
  24.  * RETURNS: TRUE if successful 
  25.  *          FALSE otherwise.
  26.  *
  27.  * CUSTOMIZATION: Re-implement
  28.  *
  29.  */
  30. static BOOL InitInstance (HANDLE hInstance, BOOL fFirstInstance)
  31. {
  32.  
  33.     :    
  34.     :
  35.  
  36.     // Initialize the method tables.
  37.     InitVTbls ();
  38.  
  39.     :
  40.     :
  41.  
  42.     // Register clipboard formats.
  43.     cfObjectLink= RegisterClipboardFormat ("ObjectLink");
  44.     cfOwnerLink = RegisterClipboardFormat ("OwnerLink");
  45.     cfNative    = RegisterClipboardFormat ("Native");
  46.  
  47.     :
  48.     :
  49.  
  50.     return TRUE;
  51. }
  52.  
  53.  
  54. /* InitVTbls
  55.  * ---------
  56.  *
  57.  * Create procedure instances for all the OLE methods.
  58.  * 
  59.  * 
  60.  * CUSTOMIZATION: Your application might not use global variables for srvrvtbl,
  61.  *                docvtbl, and objvtbl.
  62.  */
  63. void InitVTbls (void)
  64. {
  65.    typedef LPVOID (FAR PASCAL *LPVOIDPROC) (LPOLEOBJECT, LPSTR);
  66.  
  67.    // Server method table
  68.    srvrvtbl.Create          = MakeProcInstance (SrvrCreate,          hInst);
  69.    srvrvtbl.CreateFromTemplate
  70.                             = MakeProcInstance (SrvrCreateFromTemplate,hInst);
  71.    srvrvtbl.Edit            = MakeProcInstance (SrvrEdit,            hInst);
  72.    srvrvtbl.Execute         = MakeProcInstance (SrvrExecute,         hInst);
  73.    srvrvtbl.Exit            = MakeProcInstance (SrvrExit,            hInst);
  74.    srvrvtbl.Open            = MakeProcInstance (SrvrOpen,            hInst);
  75.    srvrvtbl.Release         = MakeProcInstance (SrvrRelease,         hInst);
  76.  
  77.    // Document method table
  78.    docvtbl.Close            = MakeProcInstance (DocClose,            hInst);
  79.    docvtbl.GetObject        = MakeProcInstance (DocGetObject,        hInst);
  80.    docvtbl.Execute          = MakeProcInstance (DocExecute,          hInst);
  81.    docvtbl.Release          = MakeProcInstance (DocRelease,          hInst);
  82.    docvtbl.Save             = MakeProcInstance (DocSave,             hInst);
  83.    docvtbl.SetColorScheme   = MakeProcInstance (DocSetColorScheme,   hInst);
  84.    docvtbl.SetDocDimensions = MakeProcInstance (DocSetDocDimensions, hInst);
  85.    docvtbl.SetHostNames     = MakeProcInstance (DocSetHostNames,     hInst);
  86.  
  87.    // Object method table
  88.    objvtbl.DoVerb           = MakeProcInstance (ObjDoVerb,           hInst);
  89.    objvtbl.EnumFormats      = MakeProcInstance (ObjEnumFormats,      hInst);
  90.    objvtbl.GetData          = MakeProcInstance (ObjGetData,          hInst);
  91.    objvtbl.QueryProtocol    = (LPVOIDPROC) MakeProcInstance 
  92.                                  ((FARPROC)ObjQueryProtocol,hInst);
  93.    objvtbl.Release          = MakeProcInstance (ObjRelease,          hInst);
  94.    objvtbl.SetBounds        = MakeProcInstance (ObjSetBounds,        hInst);
  95.    objvtbl.SetColorScheme   = MakeProcInstance (ObjSetColorScheme,   hInst);
  96.    objvtbl.SetData          = MakeProcInstance (ObjSetData,          hInst);
  97.    objvtbl.SetTargetDevice  = MakeProcInstance (ObjSetTargetDevice,  hInst);
  98.    objvtbl.Show             = MakeProcInstance (ObjShow,             hInst);
  99. }
  100.  
  101.  
  102. /* InitServer
  103.  * ----------
  104.  *
  105.  * Initialize the server by allocating memory for it, and calling
  106.  * the OleRegisterServer method.  Requires that the server method table
  107.  * has been properly initialized.
  108.  * 
  109.  * HWND hwnd      - Handle to the main window
  110.  * LPSTR lpszLine - The Windows command line
  111.  * 
  112.  * RETURNS: TRUE if the memory could be allocated, and the server
  113.  *          was properly registered.
  114.  *          FALSE otherwise
  115.  *
  116.  * CUSTOMIZATION: Your application might not use a global variable 
  117.  *                for srvrMain.
  118.  *
  119.  */
  120. BOOL InitServer (HWND hwnd, HANDLE hInst)
  121. {
  122.     srvrMain.olesrvr.lpvtbl = &srvrvtbl;
  123.  
  124.     if (OLE_OK != OleRegisterServer
  125.          (szClassName, (LPOLESERVER) &srvrMain, &srvrMain.lhsrvr, hInst, 
  126.           OLE_SERVER_MULTI))
  127.       return FALSE;
  128.     else
  129.       return TRUE;
  130. }
  131.  
  132.